//
//  DownloadViewController.m
//  BabyBedtimeStory
//
//  Created by qianfeng on 15-6-30.
//  Copyright (c) 2015年 张鹏毅. All rights reserved.
//

#import "DownloadViewController.h"
#import "BreakPointHttpRequest.h"
#import "NSString+Hashing.h"

@interface DownloadViewController ()
@property (nonatomic)  BreakPointHttpRequest *httpRequest;
@end

@implementation DownloadViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

-(void)startDataWithUrl:(StoryModel *)model{
    [self creatAlter:@"开始下载,请点击返回界面"];
   _httpRequest = [[BreakPointHttpRequest alloc]init];
    [_httpRequest downloadDataWithUrl:model.audio_64_url progress:^(BreakPointHttpRequest *httpRequest) {
        double s = (double)httpRequest.loadedFileSize/httpRequest.totalFileSize;
        [[NSUserDefaults standardUserDefaults] setDouble:s forKey:[model.audio_64_url MD5Hash]];
        [[NSUserDefaults standardUserDefaults] synchronize];
        if(s == 1){
            [self creatAlter:@"下载完成"];
        }
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
